Set up a twitter API to get started with twitter

Before you can download data from Twitter’s data you need to setup your API by becoming a Twitter developer. First, to become a twitter developer you need to have a twitter account. Then, you can sign up here (Figure). Once you have signed up click on the My Apps buttom on the left panel as in Figure and then click on Create a new app. You should provide a brief description about your App and a few other details. For today’s workshop we set up the the RLadies App shown in Figure. By clicking onto your App’s name you can now manage and see your settings as well as the codes that you need to get started with R. You can find the keys that you need in the Keys and Access Tokens button. Here you can find your four codes (highlighted in Figure) to use into R.

\label{fig:fig2}After signing up click on 'My Apps' and then 'Create a new App's.

After signing up click on ‘My Apps’ and then ’Create a new App’s.

\label{fig:fig3}You can now manage your App's settings.

You can now manage your App’s settings.

\label{fig:fig4}This is where you can find the access keys that you need to get started with R.

This is where you can find the access keys that you need to get started with R.

Let’s get started with RuPaul’s drag race’s tweets!

RuPaul’s drag race is an American reality competitions showing RuPaul’s search for “America’s next drag superstar”. Just to tease your curiosity, Figure shows you all the Queens which are competing in Season 9!

\label{fig:fig5}Drag queens competing in RuPaul's drag race Season 9.

Drag queens competing in RuPaul’s drag race Season 9.

Research your hashtags

The first thing to do when you want to analyse a topic using Twitter’s data is to know what is or are the most useful hastag/s that can describe your questions. This means those hastags that are most commonly used when what you are interested in is tweeted. In this example we are interested into the trends of [RuPaul’s drag race Season 9](http://logosrupaulsdragrace.wikia.com/wiki/RuPaul%27s_Drag_Race_(Season_9). A little bit of research through Twitter or Goggle is needed to define a set of good hastags. For example, we found a web page listing the top hashtags for RuPaul’s drag race https://top-hashtags.com/hashtag/rupaul/. For simplicity we will limit our search to two hastags and we decided to use one specific for season 9, #rpdr9, and a more general one, #rupaulsdragrace.

Initialize functions needed for the analyses

First, start by installing and loading all the necessary packages.

> # Packages that you need to setup your API in R and download
> # twitter data
> install.packages("twitteR")
> install.packages("ROAuth")
> install.packages("RCurl")
> install.packages("RJSONIO")
> 
> # Packages for sentiment analyses and wordclouds
> install.packages("RSentiment")
> install.packages("tm")
> install.packages("wordcloud")
> 
> # Genral R packages for plotting and manipulating data
> install.packages("tidyr")
> install.packages("dplyr")
> install.packages("ggplot2")
> install.packages("plotly")
> # Require all packages
> require("tm")
> require("wordcloud")
> require("twitteR")
> require("RSentiment")
> require("ROAuth")
> require("RCurl")
> require("RJSONIO")
> require("tidyr")
> require("dplyr")
> require("ggplot2")
> require("plotly")

Then setup your access keys as below. If you don’t remember where to find these codes see Figure\label{fig:fig4}).

> api_key <- "yourAPIKey"
> api_secret <- "yourAPISecret"
> token <- "yourToken"
> token_secret <- "yourTokenSecret"
> 
> twitteR::setup_twitter_oauth(api_key, api_secret, token, token_secret)